package com.mock.tool;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class charAlgorithm {
	
	public static void main(String args[]) {
//		sort();
//		count();
		
		replace();
	}
	//字符排序
	public static void sort() {
		String[] a= {"18877836293","13128876566","18040417332","13641874244","13750062604"};
	     Arrays.sort(a);  
	     for(int i=0;i<a.length;i++){  
	         System.out.println(a[i]);  
	     }  
	}
	
	//字符去重
	public static void replace() {
		String[] a= {"13121978957","13247193782","13247193782","13386700946","13390035557","13434128283","13450676450","13454102801","13459481518","13459481518","13459481518","13459481518","13475589592","13520214901","13520214901","13520214901","13549580719","13572296178","13572296178","13576587171","13576587171","13581681638","13581681638","13581681638","13604276741","13611164300","13613381076","13621350847","13642759223","13642759223","13642759223","13642759223","13642759223","13642759223","13642759223","13659842234","13660285871","13711581076","13719418203","13730853213","13730853213","13730853213","13736852059","13752670258","13753586290","13759545717","13759545717","13759545717","13810680397","13817881509","13822317652","13822317652","13822317652","13822317652","13822317652","13822317652","13822317652","13822317652","13828065685","13844802277","13844802277","13883814723","13883814723","13889125994","13889940143","13896273373","13910775375","13911395517","13916320448","13916320448","13924156560","13924156560","13924156560","13924156560","13983248776","15010349937","15014130385","15014130385","15017576968","15021012468","15023799328","15023799328","15023799328","15042398055","15042398055","15061668180","15131526206","15131526206","15131526206","15131526206","15131526206","15131526206","15131526206","15131526206","15131526206","15134815036","15134815036","15134815036","15134815036","15166072181","15166072181","15166072181","15173759509","15173759509","15173759509","15216204040","15230808797","15272199005","15279148945","15318998986","15328099229","15521010300","15554121559","15620759738","15620951216","15625229114","15625229114","15662483957","15715790193","15808791613","15869039667","15881233536","15937459692","15960067283","15971475193","15971475193","15971475193","15989372462","15998575357","16689010876","17625398899","17674538363","17674538363","17686670765","17782052889","18023993221","18043818087","18113607520","18113607520","18113607520","18231633230","18302068336","18320696711","18376783249","18376783249","18376783249","18501366323","18501366323","18501366323","18504307530","18504307530","18522518711","18561610179","18566290239","18576769586","18576769586","18576769586","18576769586","18576769586","18576769586","18576769586","18616834181","18616834181","18617283291","18621091512","18657375055","18664999285","18674058746","18684801861","18684801861","18684801861","18684801861","18703603597","18705722796","18705722796","18722039757","18722039757","18742485195","18775011858","18775011858","18775011858","18790378621","18809875112","18900977778","18900977778","18900977778","18900977778","18900977778","18911602188","18911602188","18999868799","18999868799",};
		
		System.out.println(checkArr(a).toString());
	}
	//字符去重
	public static List<String> checkArr(String[] str) {
//        for (String elementA : str) {
//            System.out.print(elementA + " ");
//        }
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < str.length; i++) {
        	String pp=str[i];
//        	System.err.println(pp);
            if (!list.contains(pp)) {
                list.add(pp);
            }
        }
//        String[] newStr = list.toArray(new String[1]); // 返回一个包含所有对象的指定类型的数组
        return list;
    }
	
	//数组中每个字符出现的字数
	public static void count() {
		String[] arr = new String[]{"aaa", "bbb", "ccc", "ddd", "ddd", "aaa"};

	    Map<String, Integer> map = new HashMap<>();

	    for (String str : arr) {
	    	Integer num = map.get(str); 
	    	map.put(str, num == null ? 1 : num + 1);
	    }

	    Iterator it01 = map.keySet().iterator();
	    while (it01.hasNext()) {
	      Object key = it01.next();
	      System.out.println("单词 " + key + " 出现次数 : " + map.get(key));

	    }
	}
	
	
	public  Map<String,Integer> countList (List<String> reslist){
		 Map<String,Integer> countmap = new HashMap<String, Integer>();
		 for(int i=0; i<reslist.size(); i++){
		 	 //在Map中查找关键字，如果没有就put进Map中，同时value值加1
			 if(null==countmap.get(reslist.get(i))){  
				 countmap.put(reslist.get(i), 1);
			 }else{ //如果有Map中有该元素，说明已经put过了，则直接value值计数加1
				 countmap.put(reslist.get(i), countmap.get(reslist.get(i))+1);
			 }
		 }
		return countmap;
	}

}
